package com.youlian.manager.param;

import java.lang.reflect.Field;

import android.os.Debug;
import android.provider.SyncStateContract.Constants;
import android.util.Log;

import com.youlian.common.Config;


/**
 *
 * @author simon
 *
 */
public class BaseParam {

	/** 服务名 , String , not null **/
	private String service;
	/** 用户token , String , null **/
	private String user_token;
	/** 接口版本号 , String , not null **/
	private String ver="2.0";
	/** 请求参数 , String , null **/
	private String fields;
	/** 默认为json传输格式，同时也支持xml格式 , String , not null **/
	private String format = "json";
	/** 适用版本, String , null **/
	private String version = "VIPSHOP,VIPCLUB";
	/** 输入字符码 , String , null **/
	private String _input_charset = "UTF-8";
	/** 输出字符码, String , null **/
	private String _output_charset = "UTF-8";
	/** 页码, Integer , null */
	private int page = 1;
	/** 每页大小, Integer , null **/
	private int page_size = 10;
	/** 接口请求时间戳 , String , not null **/
	public long timestamp;


	class Api{
		public String api_secret;
		public String apiKey;
	}


	public String getService() {
		return service;
	}

	public void setService(String service) {
		this.service = service;
	}

	public String getUser_token() {
		return user_token;
	}

	public void setUser_token(String user_token) {
		this.user_token = user_token;
	}

	/**
	 *
	 * @return
	 */
	public String getApi_key(String apiKey) {
		return apiKey;
	}


	public String getApi_secret(String api_secret){
		return api_secret;
	}

	public String getFields() {
		return fields;
	}

	public void setFields(String fields) {
		this.fields = fields;
	}

	/**
	 * 通过反射机制设置字段
	 * @param <T>
	 * @param c
	 */
	public <T> void setFields(Class<T> c) {

		StringBuilder builder = new StringBuilder();

		Field[] fieldArray = c.getDeclaredFields();
		if(null != fieldArray){
			for(Field f : fieldArray){
				builder.append(f.getName());
				builder.append(",");
			}
		}else{
			builder.append(",");
		}

		String fieldsStr = builder.toString();
		fieldsStr = fieldsStr.substring(0, fieldsStr.length()-1);

		if(Debug.isDebuggerConnected()){
			Log.i(" BaseParam setFields : ", fieldsStr);
		}
		this.fields = fieldsStr;
	}

	public <T> void setFields(T... values) {

		StringBuilder builder = new StringBuilder();
		for(int i=0;i<values.length;i++)
		{
			builder.append(values[i]);
			if(i!=values.length-1)
				builder.append(",");
		}

		String fieldsStr = builder.toString();

		if(Debug.isDebuggerConnected()){
			Log.i(" BaseParam setFields : ", fieldsStr);
		}
		this.fields = fieldsStr;
	}

	public String getFormat() {
		return format;
	}

	public void setFormat(String format) {
		this.format = format;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public String get_input_charset() {
		return _input_charset;
	}

	public void set_input_charset(String _input_charset) {
		this._input_charset = _input_charset;
	}

	public String get_output_charset() {
		return _output_charset;
	}

	public void set_output_charset(String _output_charset) {
		this._output_charset = _output_charset;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getPage_size() {
		return page_size;
	}

	public void setPage_size(int page_size) {
		this.page_size = page_size;
	}

	public String getVer() {
		return ver;
	}

	public void setVer(String ver) {
		this.ver = ver;
	}

}
